#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100;
const int M = 1e9 + 7;

int t, n;
string s;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin>>t;
    while(t--){
        cin>>n>>s;
        int sum =0, cnt = 0;
        for(int i=0;i<n;i++) {
            sum += s[i] - '0';
            if (s[i] != '0') cnt++;
        }
        cout << sum + cnt - 1 + (s[n-1] == '0') << endl;
    }
    return 0;
}